package com.itsfoodme.login;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.HttpResponseException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

public class istFoodApi {
        
        public boolean postDataL(String id, String Service, String Request){
        // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://adeektos.com/jpkarty/api2/api.php");

    try {
        // Add your data
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("rquest", Request));
        nameValuePairs.add(new BasicNameValuePair("uniqId", id));
        nameValuePairs.add(new BasicNameValuePair("service", Service));
        
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httppost);
        BasicResponseHandler myHandler = new BasicResponseHandler();

        try {
            String resultado = myHandler.handleResponse(response);
            if(resultado==null) return false;
            Log.i("api login: ",resultado);
            String idT= " ";
                try{
                	JSONObject J = new JSONObject(resultado);
                	idT = J.getString("status");
                }catch(JSONException a){
                	a.printStackTrace();
                }
                if(idT=="Ok"){
                        return true;
                }
        } catch (HttpResponseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
    } catch (IOException e) {
        // TODO Auto-generated catch block
    }
    return false;
        } 
        
        public boolean postDataI(String id, String Service, String Request, String [] T){
                // Create a new HttpClient and Post Header
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("http://adeektos.com/jpkarty/api2/api.php");

            try {
                // Add your data
                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
                nameValuePairs.add(new BasicNameValuePair("rquest", Request));
                nameValuePairs.add(new BasicNameValuePair("uniqId", id));
                nameValuePairs.add(new BasicNameValuePair("service", Service));
                nameValuePairs.add(new BasicNameValuePair("Udata[0]", T[2]));
                nameValuePairs.add(new BasicNameValuePair("Udata[1]", T[3]));
                nameValuePairs.add(new BasicNameValuePair("Udata[2]", T[4]));
                nameValuePairs.add(new BasicNameValuePair("Udata[3]", T[5]));
                nameValuePairs.add(new BasicNameValuePair("Udata[4]", T[6]));
                nameValuePairs.add(new BasicNameValuePair("Udata[5]", T[7]));
                nameValuePairs.add(new BasicNameValuePair("Udata[6]", T[8]));
                nameValuePairs.add(new BasicNameValuePair("Udata[7]", T[9]));
                nameValuePairs.add(new BasicNameValuePair("Udata[8]", T[10]));
                nameValuePairs.add(new BasicNameValuePair("Udata[9]", T[11]));
                nameValuePairs.add(new BasicNameValuePair("Udata[10]", T[12]));
                
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                HttpResponse response = httpclient.execute(httppost);
                BasicResponseHandler myHandler = new BasicResponseHandler();
                
                try {
                    String resultado = myHandler.handleResponse(response);
                    if(resultado==null) return false;
                    String idT= " ";
                    try{
                    	JSONObject J = new JSONObject(resultado);
                    	idT = J.getString("status");
                    }catch(JSONException a){
                    	a.printStackTrace();
                    }
                    if(idT=="Ok"){
                                return true;
                    }
                } catch (HttpResponseException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
            } catch (IOException e) {
                // TODO Auto-generated catch block
            }
            return false;
        } 

}